# -*- coding: utf-8 -*-
from datetime import timedelta

from odoo import models, fields, api


class HrRecordWizard(models.TransientModel):
    _name = 'hr.record.wizard'
    date=fields.Date(string=u'日期',default=fields.Date.today)
    start_date = fields.Date(string=u'开始日期')
    end_date = fields.Date(string=u'结束日期', default=fields.date.today())
    department_id = fields.Many2one('hr.department')
    employee_id = fields.Many2one('hr.employee')

    def action_confirm(self):
        if not self.department_id:
            employee_ids=self.env['hr.employee'].search([])
        else:
            employee_ids = self.env['hr.employee'].search([('department_id','=',self.department_id.id)])
        if self.employee_id:
            employee_ids=self.employee_id
        domain=[('card_date_time','>=',self.start_date),('card_date_time','<=',self.end_date)]
        if employee_ids:
            domain+=[('employee_id','in',employee_ids.ids)]
        records=self.env['hr.record'].search(domain)
        records.create_or_update_hr_attendance()

    # def action_confirm(self):
    #     if self.date:
    #         records=self.env['hr.record'].search([('date','=',self.date)])
    #     else:
    #         records=self.env['hr.record'].search([])
    #
    #     records.create_or_update_hr_attendance()